package com.mzy.linear_struct.hot100.回溯;

import java.util.*;
import java.util.stream.Collector;
import java.util.stream.Collectors;

/**
 * @Author: mizy3
 * @Date: 2024/09/08/下午7:31
 * @Description:
 */
public class Pro257二叉树的所有路径 {
    public List<String> binaryTreePaths(TreeNode root) {
        List<String> ans = new ArrayList<>();
        String path = "";

        backtracking(root, ans, path);
        return ans;
    }

    private void backtracking(TreeNode root, List<String> ans, String path) {
        if (root == null) return;
        if (root.left == null && root.right == null) {
            ans.add(path + root.val);
            return;
        }

        backtracking(root.left, ans, path + root.val + "->");
        backtracking(root.right, ans, path + root.val + "->");
    }
}



























